package cn.wolfcode.crm.query;

import cn.wolfcode.crm.domain.Accident;
import com.alibaba.druid.util.StringUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Calendar;
import java.util.Date;

@Setter
@Getter
public class AccidentMapperQueryObject extends QueryObject {

    private String keyword; //根据报案人姓名和/手机/邮箱进行查询

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDate;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;

    private int status= Accident.ENTIRE;   //根据状态值查询数值

    //对结束时间进行计算
    public void setEndDate(Date endDate) {
        if (endDate != null) {

            Calendar cal = Calendar.getInstance();
            cal.setTime(endDate);
            cal.add(Calendar.DATE, 1);
            cal.add(Calendar.SECOND, -1);
            this.endDate = cal.getTime();
        }else {
            this.endDate=endDate;
        }

    }

    public String getKeyword(){
        if (StringUtils.isEmpty(keyword)){
            return null;
        }
        return  keyword;
    }
}
